package javaAdvanced;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

/**
 * @author cuiH
 * Date: 13-10-22
 */
public class Logging {
    /*
    * 通过一个简单的例子测试了日志的功能，其可以将捕获的错误均显示为错误日志
    * 捕捉到异常e进行处理
    * */
    private static Logger logger = Logger.getLogger("Logging");
    static void logException(Exception e){
        StringWriter trace = new StringWriter();
        e.printStackTrace(new PrintWriter(trace));
        logger.severe("崔涣错误日志:"+trace.toString());
    }

    public static void main(String[] args) {
        try {
            throw new NullPointerException();
        } catch (NullPointerException e) {
            logException(e);
        }
    }

}
